import 'package:flutter/widgets.dart';
import 'package:flutter/services.dart';
typedef MapCallback = void Function(Map args);

class NativeViewE extends StatelessWidget {
  final MapCallback? callAction;
  NativeViewE({
    Key? key, 
    required this.callAction,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    const String viewType = 'plugins.flutter/flnative_view';
    final Map<String, dynamic> creationParams = <String, dynamic>{
      'showText': 'Native Label, Text from Flutter',
    };
    Future<dynamic> platformCallHandler(MethodCall call) async {
      String methodName = call.method;
      print(methodName);
      Map args = call.arguments;
      callAction!(args);
    }
    const platform = MethodChannel('plugins.methods/flnative_plugin');
    platform.setMethodCallHandler((call) => platformCallHandler(call));
    return UiKitView(
      viewType: viewType,
      layoutDirection: TextDirection.ltr,
      creationParams: creationParams,
      creationParamsCodec: const StandardMessageCodec(),
    );
  }
}
